Array.prototype.remove = function (pred) {
    res = [].concat(this.filter(pred));
    rest = [].concat(this.filter(v => !pred(v)))
    this.length = 0;
    for (var i = 0; i < rest.length; i += 1000) {
        this.push(...rest.slice(i, i + 1000))
    }
    return res;
}
